﻿package tools;

import java.util.StringTokenizer;

public class StringTokenizerDemo {

	public static void main(String[] args){
		String str="a,ab,abc,abcd,abcde,abcdef,abcdefg";
		//StringTokenizer
		StringTokenizer st=new StringTokenizer(str, ",");
		int len=st.countTokens();
		System.out.println("len="+len);
		String[] strarray=new String[10];
		int i=0;
		while(st.hasMoreTokens()){
			strarray[i]=st.nextToken();
			System.out.print(" "+strarray[i]);
		}
		System.out.println();
		//建议用这个
		String[] strsp=str.split(",");
		for(int j=0;j<strsp.length;j++){
			System.out.print(" "+strsp[j]);
		}
	}
}
